package stu.lee.controller;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import stu.lee.entity.Admin;
import stu.lee.entity.Miui;
import stu.lee.service.IMiuiService;
import stu.lee.stu.lee.core.common.Utils.GetJedis;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.logging.Filter;

@Controller
@RequestMapping("/miui")
public class MiuiController {
    @Resource
    private IMiuiService miuiService;

    @RequestMapping(value = "/showAllMiui")
    @ResponseBody
    public List<Miui> showAllMiui() {
        if (StringUtils.isNotBlank(GetJedis.getJedis().get("miuis"))) {
            final List<Miui> miuis = miuiService.showAllMiui();

            new Thread() {
                public void run() {
                    writeRedis(miuis);
                }
            }.start();
            return miuis;

        } else {
//            GetJedis.getJedis().lrange("miuis", 0, -1);
            return null;
        }

    }

    public void writeRedis(List<Miui> o) {
        for (Miui m : o) {
            GetJedis.getJedis().lpush("miuis", m.toString());
        }
    }

    @RequestMapping(value = "/index")
    public String toIndex() {
        return "forward:/index.jsp";
    }


    @Test
    public void test() {


    }
}
